package com.limeng.datastruts.work;

public class GoldCalculate {

    private static final int MAX_MAN_COUNT = 10;

    public static void main(String[] args) {
        GoldPile pile1 = new GoldPile(150,2);
        GoldPile pile2 = new GoldPile(200,3);
        GoldPile pile3 = new GoldPile(250,3);
        GoldPile pile4 = new GoldPile(500,5);
        GoldPile pile5 = new GoldPile(600,7);
        GoldPile[] piles = {pile1,pile2,pile3,pile4,pile5};
        GoldCalculate goldCalculate = new GoldCalculate();
        System.out.println("能挖出最大量黄金是"+goldCalculate.calGoldStore(piles)+"kg");
    }

    private double calGoldStore(GoldPile[] piles){
        if(piles==null|| piles.length==0) return 0;

        double[][]dp=new double[piles.length+1][MAX_MAN_COUNT+1];
        for (int i = 1; i <= piles.length; i++) {
            GoldPile pile = piles[i-1];
            for (int j = 1; j <= MAX_MAN_COUNT; j++) {
                if (j>=pile.man){
                    dp[i][j] = Math.max(dp[i-1][j],pile.gold+dp[i-1][j-pile.man]);
                }else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
        return dp[piles.length][MAX_MAN_COUNT];
    }

    static class GoldPile{
        private double gold;
        private int man;

        public GoldPile(double gold, int man) {
            this.gold = gold;
            this.man = man;
        }
    }
}
